using Senparc.Weixin.HttpUtility;
using Senparc.Weixin.MP.CommonAPIs;
using System;
namespace Senparc.Weixin.MP.AppStore
{
	public static class AppStoreOAuth
	{
		private static string Domain
		{
			get
			{
				return Config.IsDebug ? "http://localhost:12222" : "http://www.weiweihi.com";
			}
		}
		public static string GetAuthorizeUrl(int weixinId, string clientId, string redirectUrl, string state, string responseType = "code")
		{
			return string.Format(AppStoreOAuth.Domain + "/OAuth2/Authorize?weixinId={0}&clientId={1}&RedirectUri={2}&response_type=code&state={3}", new object[]
			{
				weixinId,
				clientId,
				redirectUrl.UrlEncode(),
				state
			});
		}
		public static OAuthAccessTokenResult GetAccessToken(string clientId, string clientSecret, string code, string grantType = "authorization_code")
		{
			string urlFormat = string.Format(AppStoreOAuth.Domain + "/OAuth2/AccessToken?clientId={0}&clientSecret={1}&code={2}&grantType={3}", new object[]
			{
				clientId,
				clientSecret,
				code,
				grantType
			});
			return CommonJsonSend.Send<OAuthAccessTokenResult>(null, urlFormat, null, CommonJsonSendType.GET, 10000, false);
		}
	}
}
